package gosnoopers.fr;

import java.util.Locale;

import android.os.Bundle;
import android.app.Activity;

import android.content.Intent;
import android.content.res.Configuration;
import android.util.Log;

import android.view.View;
import android.view.Window;

import android.view.View.OnClickListener;

import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class Language extends Activity {
	private String current_lang = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_language);
	    TextView text = (TextView) findViewById(R.id.text_view_landing_page_header);
	    
        text.setText("Choose Language");
        final CheckBox cbEn = (CheckBox) findViewById(R.id.checkBoxEn);
        final CheckBox cbFr = (CheckBox) findViewById(R.id.checkBoxFr);
        if(HomePage.language.equals("en")){
        	cbEn.setChecked(true);
        } else {
        	cbFr.setChecked(true);
        }
        current_lang = HomePage.language;
       
        cbEn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(cbEn.isChecked()) {
					current_lang = "en";					
					cbFr.setChecked(false);
				}
					
			}
		});
        cbFr.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(cbFr.isChecked()){
					current_lang = "fr";
					cbEn.setChecked(false);
				}
			}
		});
        
        ImageView image_done = (ImageView) findViewById(R.id.image_done);
        image_done.setClickable(true);
        image_done.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            		HomePage.language = current_lang;
            		new SessionManager(getApplicationContext()).setLanguage(current_lang);
            		Locale locale = new Locale(current_lang);
        		    Locale.setDefault(locale);
        		    Configuration config = new Configuration();
        		    config.locale = locale;
        		    getApplicationContext().getResources().updateConfiguration(config, null);
            	
				Intent goToNextActivity = new Intent(getApplicationContext(), HomePage.class);
				startActivity(goToNextActivity);
            }
        });
	}
	
	
    
}

